import { faker } from "@faker-js/faker";
import { supabase } from "../utils/supabase.js";
function generateClass() {
  const classNum = faker.number.int({ min: 1, max: 20 });
  const gradeNum = faker.number.int({ min: 1, max: 12 });
  return `${classNum}|${gradeNum}`;
}

export function generateTeacher() {
  const classCount = faker.number.int({ min: 1, max: 5 }); // 每个教师可以教的班级数量
  const classInCharge = new Array(classCount)
    .fill(0)
    .map(() => generateClass());

  return {
    name: faker.person.fullName(),
    class_in_charge: JSON.stringify(classInCharge),
    gender: faker.person.sex(),
    avatar: faker.image.avatar(),
  };
}

export function generateTeachers(count = 5) {
  return new Array(count).fill(0).map(() => generateTeacher());
}

export async function insertTeachers(count = 5) {
  const teachers = generateTeachers(count);
  const { data, error } = await supabase
    .from("teacher")
    .insert(teachers)
    .select();
  if (error) {
    console.log(error.message);
    return;
  }
  return data;
}
